package com.example.demo.jpa.person;

import com.example.demo.jpa.person.dto.PersonCommand;
import com.example.demo.jpa.person.dto.PersonDTO;
import com.example.demo.jpa.person.service.Personservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/person")
public class PersonController {

    @Autowired
    Personservice personservice;

    @GetMapping("/{id}")
    public PersonDTO getPersonById(@PathVariable Long id){return personservice.findPersonById(id);}

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public PersonDTO createPerson(@RequestBody PersonCommand personCommand){return personservice.createPerson(personCommand);}

    @PutMapping("/{id}")
    public PersonDTO updatePerson(@PathVariable Long id,@RequestBody PersonCommand personCommand){
        return personservice.updatePerson(id,personCommand);
    }

    @DeleteMapping("/{id}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void deletePersonById(@PathVariable Long id){
        personservice.deletePersonById(id);
    }
}
